package com.ruoyi.web.controller.guarantee;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.guarantee.domain.BLetter;
import com.ruoyi.guarantee.service.IBLetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出函机构Controller
 *
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/system/letter")
public class BLetterController extends BaseController {
    @Autowired
    private IBLetterService bLetterService;

    /**
     * 查询出函机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:list')")
    @GetMapping("/list")
    public TableDataInfo list(BLetter bLetter)
    {
        startPage();
        List<BLetter> list = bLetterService.selectBLetterList(bLetter);
        return getDataTable(list);
    }

    /**
     * 查询出函机构列表
     */
    @GetMapping("/getBLetterList")
    public AjaxResult getList()
    {
        BLetter bLetter = new BLetter();
        List<BLetter> list = bLetterService.selectBLetterList(bLetter);
        return AjaxResult.success(list);
    }

    /**
     * 导出出函机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:export')")
    @Log(title = "出函机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BLetter bLetter)
    {
        List<BLetter> list = bLetterService.selectBLetterList(bLetter);
        ExcelUtil<BLetter> util = new ExcelUtil<BLetter>(BLetter.class);
        util.exportExcel(response, list, "出函机构数据");
    }

    /**
     * 获取出函机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:letter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bLetterService.selectBLetterById(id));
    }

    /**
     * 新增出函机构
     */
    @PreAuthorize("@ss.hasPermi('system:letter:add')")
    @Log(title = "出函机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BLetter bLetter)
    {
        return toAjax(bLetterService.insertBLetter(bLetter));
    }

    /**
     * 修改出函机构
     */
    @PreAuthorize("@ss.hasPermi('system:letter:edit')")
    @Log(title = "出函机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BLetter bLetter)
    {
        return toAjax(bLetterService.updateBLetter(bLetter));
    }

    /**
     * 删除出函机构
     */
    @PreAuthorize("@ss.hasPermi('system:letter:remove')")
    @Log(title = "出函机构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bLetterService.deleteBLetterByIds(ids));
    }
}
